package com.mallcai.bigdata.ladon.controller.system.form;

import com.mallcai.bigdata.ladon.controller.BaseForm;
import com.mallcai.bigdata.ladon.dpl.entity.system.Resource;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-06-24 14:05.
 * Modify:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ResForm extends BaseForm {
    @NotNull(message = "父节点不能为空", groups = {AddCheck.class, EditCheck.class})
    private Long    parentId;
    @NotNull(message = "主键Id不能为空", groups = {IdCheck.class})
    private Long    resId;
    @NotBlank(message = "资源名称不能为空", groups = {AddCheck.class, EditCheck.class})
    private String  name;
    @NotNull(message = "资源类型不能为空", groups = {AddCheck.class, EditCheck.class})
    private Integer type;
    private String  path;     // 资源路径
    private String  authCode; // 权限编码

    private String icon;
    private String comment;

    public interface IdCheck {
    }

    public interface AddCheck {
    }

    public interface EditCheck {
    }


    public Resource toEntity() {
        Resource r = new Resource();
        r.setId(resId);
        r.setParentId(parentId);
        r.setName(name);
        r.setPath(path);
        r.setType(type);
        r.setAuthCode(authCode);
        r.setIcon(icon);
        r.setComment(comment);
        return r;
    }
}
